package com.warmlight.voicepacket.utils;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

public class ShareUtils {


    /**
     *
     * @param context
     * @param share_media
     * @param url
     * @param title
     * @param desc
     * @param imgurl
     * @param umShareListener
     */
    public static void shareWeb(Context context,SHARE_MEDIA share_media,
                                String url, String title , String desc,
                                String imgurl,UMShareListener umShareListener){
        /**
         * 判断url是否为空，来执行分享图片还是连接
         */
        if (TextUtils.isEmpty(url)){

            UMImage image = new UMImage(context, imgurl);//网络图片
            image.compressStyle = UMImage.CompressStyle.SCALE;//大小压缩，默认为大小压缩，适合普通很大的图
            image.compressStyle = UMImage.CompressStyle.QUALITY;

            if ((!TextUtils.isEmpty(imgurl)) && imgurl.contains("http")) {

                UMImage thumb =  new UMImage(context, imgurl);
                image.setThumb(thumb);  //缩略图
            }

            new ShareAction((Activity) context)
                    .setPlatform(share_media)//传入平台
                    .withMedia(image)//分享内容
                    .setCallback(umShareListener)
                    .share();
            return;
        }

        UMWeb web = new UMWeb(url);
        web.setTitle(title);//标题
        if ((!TextUtils.isEmpty(imgurl)) && imgurl.contains("http")) {
//            UMImage image = new UMImage(ShareActivity.this, "imageurl");//网络图片
//            UMImage image = new UMImage(ShareActivity.this, file);//本地文件
//            UMImage image = new UMImage(ShareActivity.this, R.drawable.xxx);//资源文件
//            UMImage image = new UMImage(ShareActivity.this, bitmap);//bitmap文件
//            UMImage image = new UMImage(ShareActivity.this, byte[]);//字节流
            UMImage thumb =  new UMImage(context, imgurl);
//            image.setThumb(thumb);
            web.setThumb(thumb);  //缩略图
        }
        web.setDescription(desc);//描述
        new ShareAction((Activity) context)
                .setPlatform(share_media)//传入平台
                .withMedia(web)//分享内容
                .setCallback(umShareListener)
                .share();
    }



}
